ActiveAdmin.register Result do
 
  actions :all, :except => [:new, :edit]
  menu :label => "All scanning results", :priority => 2, :parent => "Scan"

  filter :scan, :as => :select, :collection => Scan.all.collect {|s| [s.scan_name.to_s, s.scan_name.to_s]}
  filter :system, :as => :select, :collection => Scan.all.collect {|s| [s.system.to_s, s.system.to_s]}

  scope :all
  scope :false_positives
  scope :positives, :default => true

  index do

    column t("results.form.regex"), :pattern_type
    column t("results.form.pattern"), :pattern
    column t("results.form.file"), :file
    column t("results.form.database"), :db
    column t("results.form.table"), :tbl
    column t("results.form.column"), :col
    column t("results.form.row"), :row
    column t("results.form.byte_offset"), :offset
    column t("results.form.is_false"), :is_false
  end

  controller do
    def set_as_false

      result = Result.find(params[:id])
      result.is_false = true
      
      Falsepositive.create(:scan => result.scan, :tracker => result.tracker, :domain => result.domain, 
          :pattern => result.pattern, :file => result.file, :offset => result.offset, :md5 => result.md5)
      
      render :text => result.save()
    end
  end
end
